/**
* All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
*
* MpmProjectProblemService
* 项目问题
*
* 修改纪录
* 2021-08-04 版本：1.0 xinfushuo 创建。
* @version 版本：1.0
* @author 作者：xinfushuo
* 创建日期：2021-08-04
*/
package com.topscomm.mpm.service.impl;

import com.topscomm.pub.vo.Page;
import com.topscomm.basic.exception.ServiceException;
import com.topscomm.pub.vo.Query;
import com.topscomm.tap.TapEntity;
import com.topscomm.tap.common.DatacodeCache;
import com.topscomm.tap.common.SessionUserBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.topscomm.mpm.service.IMpmProjectProblemService;
import com.topscomm.mpm.service.impl.auto.MpmProjectProblemServiceAuto;
import com.topscomm.basic.BasicEntity;
import com.topscomm.mpm.pojo.MpmProjectProblemEntity;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service(value = "mpmProjectProblemService")
@Scope(value = "singleton")
public class MpmProjectProblemService extends MpmProjectProblemServiceAuto implements IMpmProjectProblemService {
	@Autowired
	DatacodeCache datacodeCache;
	/**
	 * @author: xinfushuo
	 * @date: 2021-08-04
	 * @param entity
	 * @throws ServiceException
	 * @description:单号生成
	 * @modify:
	 */
	@Override
	protected void beforeInsert(BasicEntity entity){
		super.beforeInsert(entity);
		GenerateIDAndCode(entity,"PP", MpmProjectProblemEntity.FieldOrdercode);
	}
	/**
	 * @description: 赋值编号 docno改为提交时创建
	 * @author xinfushuo
	 * @param
	 * @throws
	 * @return
	 * @date 2021/9/10
	 * @modify
	 */
	@Override
	protected void beforeSubmit(TapEntity entity, SessionUserBean sessionUserBean){
		super.beforeSubmit(entity,sessionUserBean);
		//  赋值单号和项目编号
		GenerateIDAndCode(entity,"PP", MpmProjectProblemEntity.FieldOrdercode);
	}

	/**
	 * @author: xinfushuo
	 * @date: 2021-08-16
	 * @param mapRow
	 * @description:设置字段显示值
	 * @modify:
	 */
	@Override
	public void setDispFields(Map<String, Object> mapRow, DatacodeCache datacodeCache) {
		super.setDispFields(mapRow,datacodeCache);
		String temp;
		//流程名字显示
		if (mapRow.get("flowid") != null) {
			temp = mapRow.get("flowid").toString();
			mapRow.put("dispflowid", datacodeCache.getValueDynamic("ApprovalFlow_MpmProjectProblem", temp, "id", "name"));
		}
		//项目问题等级显示 关键or一般
		if (mapRow.get("problemlevel") != null) {
			temp = mapRow.get("problemlevel").toString();
			mapRow.put("dispproblemlevel", datacodeCache.getValueDynamic("MpmProjectProblemLevel", temp, "code", "name"));
		}

		//配置项目等级显示值
		if (mapRow.get("projectlevel") != null) {
		 temp = mapRow.get("projectlevel").toString();
			mapRow.put("dispprojectlevel", datacodeCache.getValueDynamic("MpmProjectLevel", temp, "code", "name"));
		}
	}

	/**
	 * @author: zhangjunyao
	 * @date: 2021-12-1
	 * @param: String, Query
	 * @description:返回该用户该项目下所有待办审批问题
	 * @modify:
	 */
	@Override
	@Transactional
	public Page waitApprovalList(String sqlWhere, Query query) {
		int totalCount = this.getCount(sqlWhere);
		List<Map<String, Object>> tempList = null;
		if (query.getPageSize() > 0) {
			tempList = this.queryMapForPage(sqlWhere, query.getCurrentPage(), query.getPageSize(),
					query.getSidx(), query.getSord());
		} else
			tempList = this.queryMapByWhere(sqlWhere);
		return new Page(tempList, totalCount, query.getPageSize(), query.getCurrentPage());
	}
}
